package com.example.fruitmatching;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.GridLayout;
import android.widget.ToggleButton;

import com.example.fruitmatching.data.Fruit;

public class DemoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);

        GridLayout gridLayout = findViewById(R.id.demo_layout);

        Fruit[][] fruits = new GameAlgorithm().initialGameInterface(4, 4);
        for (int i = 0; i < fruits.length; i++) {
            for (int j = 0; j < fruits[i].length; j++) {
                Fruit fruit = fruits[i][j];
                ToggleButton tb = new ToggleButton(this);//新创建一个控件时，需要传入一个上下文对象
                tb.setBackgroundResource(fruit.getImageId());
                tb.setText("");//水果图片上不需要文字
                tb.setTextOn("");
                tb.setTextOff("");
                tb.setTag(fruit);//可以将

                gridLayout.addView(tb,200, 200);
            }
        }

    }
}